#include "CGICommandList.h"

#include "DynamicCGI.h"

namespace Alice {
	CGICommandListExecutor gCGICommandListExecutor;
	CGICommandListBase::CGICommandListBase() {
		CommandLink = &Root;
	}
	ERHIPipeline CGICommandListBase::SwitchPipeline(ERHIPipeline Pipeline)
	{
		GraphicsContext = &CGICommandListImmediate::Get().GetContext();// gDynamicCGI->CGIGetDefaultContext();
		return ERHIPipeline::Graphics;
	}
	void CGICommandList::BeginRenderPass(const CGIRenderPassInfo* InInfo, const TCHAR* Name)
	{
		GetContext().RHIBeginRenderPass(InInfo,Name);
	}
	void CGICommandList::EndRenderPass()
	{
		GetContext().RHIEndRenderPass();
	}
	void CGICommandList::DrawPrimitive(uint32 BaseVertexIndex, uint32 NumPrimitives, uint32 NumInstances)
	{
		{
			//check(IsOutsideRenderPass());
			//if (Bypass())
			{
				GetContext().RHIDrawPrimitive(BaseVertexIndex, NumPrimitives, NumInstances);
				return;
			}
			//ALLOC_COMMAND(FRHICommandDrawPrimitive)(BaseVertexIndex, NumPrimitives, NumInstances);
		}
	}
	void CGICommandList::SetGraphicsPipelineState(FGraphicsPipelineState* GraphicsPipelineState, const FBoundShaderStateInput& ShaderInput, uint32 StencilRef, bool bApplyAdditionalState)
	{
		CGIGraphicsPipelineState*pipelineState=GraphicsPipelineState->mCGIGraphicsPipelineState;
		GetContext().RHISetGraphicsPipelineState(pipelineState,StencilRef,bApplyAdditionalState);
	}

	CGICommandListImmediate& CGICommandListImmediate::Get()
	{
		return CGICommandListExecutor::GetImmediateCommandList();
	}
	void CGICommandListImmediate::BeginDrawingViewport(CGIViewport* Viewport, CGITexture* RenderTargetRHI)
	{
		
	}
	void CGICommandListImmediate::EndDrawingViewport(CGIViewport* Viewport, bool bPresent, bool bLockToVsync)
	{
		GetContext().RHIEndDrawingViewport(Viewport,bPresent,bLockToVsync);
	}

	CGICommandListImmediate& CGICommandListExecutor::GetImmediateCommandList()
	{
		return gCGICommandListExecutor.mCommandListImmediate;
	}
	CGICommandListImmediate& GetImmediateCommandList_ForRenderCommand()
	{
		return gCGICommandListExecutor.mCommandListImmediate;
	}

}
